const path = require('path');
function resolve (dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  lintOnSave: true,
  publicPath: './',
  productionSourceMap: false,
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('Components', resolve('src/components'))
      .set('Config', resolve('src/config'))
      .set('Core', resolve('src/core'))
      .set('Store', resolve('src/store'))
      .set('View', resolve('src/view'))
      .set('Mixin', resolve('src/mixin'))
      .set('Utils', resolve('src/utils'))

    if (process.env.npm_config_report) {
      config
        .plugin('webpack-bundle-analyzer')
        .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
    }
    config.plugin('ThemeColorReplacerPlugin').use(require('./theme-webpack')())
  },
  devServer: {
    port: 9001,
    proxy: {
      '/api': {
        target: 'https://dev.iotbapi.fanhuashu.com/',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  },
  configureWebpack: {
    externals: {
      clientConfig: 'window.clientConfig'
    },
  },
  css: {
    loaderOptions: {
      sass: {
        data: `@import "@/common/css/variable.scss";`
      },
      less: {
        modifyVars: {
          /* less 变量覆盖，用于自定义 ant design 主题 */
          'primary-color': 'rgb(225,16,45)',
          // 'link-color': '#F5222D',
          // 'border-radius-base': '4px',
        },
        javascriptEnabled: true,
      }
    }
  }
}
